/*
	File: data/scripts/scene-ui_advanced-sprites.nut
	Author: GameStart3d.com
*/

/*!
	@short	SceneUIAdvancedSprites
	@author	GameStart3d.com
*/
class	SceneUIAdvancedSprites
{
	texture 		=	0
	sprites			=	0
	ui				=	0
	phase			=	0.0
	master_sprite	=	0

	function	OnSetup(scene)
	{
		print("SceneUISprites::OnSetup()")
		ui = SceneGetUI(scene)

		//	Dummy Window
		local	tx = 1280.0 * 0.5, ty = 960.0 * 0.5
		master_sprite = UIAddWindow(ui, -1, tx, ty, 0, 0)

		sprites = []
		local n, x, y, w, h
		x = 16
		y = 480 

		//	Test the line below with "data/assets/ui_popn_twinbee_pink_sprite.png"
		texture = ResourceFactoryLoadTexture(g_factory, "data/assets/ui_popn_twinbee_rainbow_bell_sprite.png")
		w = TextureGetWidth(texture)
		h = TextureGetHeight(texture)

		for(n = 0; n < 16; n++)
		{

			if (n == ((n / 2.0).tointeger() * 2))
				y = 480
			else
				y = 480 + (h * 2.0)

			sprites.append(UIAddSprite(ui, -1, texture, x - tx, y - ty, w, h))
			SpriteSetPivot(sprites[n], w * 0.5, h * 0.5)
			SpriteSetParent(sprites[n], master_sprite)
			x += w * 1.25
		}

		local spr = UIAddSprite(ui, -1, texture, 640 - tx, 200 - ty, w, h)
		SpriteSetSize(spr, w * 3, h)
		SpriteSetPivot(spr , w * 3 * 0.5, h * 0.5)
		SpriteSetScale(spr, 4, 4)
		SpriteSetParent(spr, master_sprite)

	}

	function	OnRenderUser(scene)
	{
		RendererDrawCross(g_render, Vector(0,0,5))
	}

	function	OnUpdate(scene)
	{
		local	dt_frame = 1.0 / 60.0
		phase += 90.0 * dt_frame

		SpriteSetRotation(master_sprite, PI * 0.1 * sin(Deg(phase)))
		SpriteSetOpacity(master_sprite, Clamp(sin(Deg(phase * 0.125)), 0.5 ,1.0))

		foreach(idx, spr in sprites)
		{
			local	scale = (sin(Deg(phase + idx * 15.0)) + 2.0) * 0.5 + 0.5
			SpriteSetScale(spr, scale, scale)
			SpriteSetRotation(spr, PI * 0.1 * sin(Deg(phase + idx * 20.0)))
			SpriteSetOpacity(spr, Clamp(sin(Deg(phase * 2.125 + idx * 10.0)), 0.5 ,1.0))
		}
	}
}

